package com.ddwl.gate.dao;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.common.constant.MobileConfigEnum;
import com.ddwl.gate.mapper.MobileRechargeRecordMapper;
import com.ddwl.gate.model.MobileRechargeRecord;
import com.ddwl.schema.bo.gate.MobileRechargeRecordPageBo;
import com.ddwl.schema.vo.order.StatisticsAmountVo;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author hemiaojun
 * @Date 2020/9/23 19:37
 */
@Repository
public class MobileRechargeRecordDao extends TkDao<MobileRechargeRecordMapper, MobileRechargeRecord> {

    @Resource
    private MobileRechargeRecordMapper mobileRechargeRecordMapper;

    public List<MobileRechargeRecord> getList(MobileRechargeRecordPageBo bo) {
        Example example = getExample();
        example.and().andEqualTo("userId", bo.getUserId())
                .andLike("mobile", MySqlUtil.rightLike(bo.getMobile()))
                .andLike("serialno", MySqlUtil.rightLike(bo.getSerialno()))
                .andEqualTo("status", bo.getStatus())
                .andLike("bizOrderId", MySqlUtil.rightLike(bo.getBizOrderId()))
                .andGreaterThanOrEqualTo("gmtCreated", bo.getStartTime())
                .andLessThan("gmtCreated", bo.getEndTime());
        if (bo.getProduct() != null && !bo.getProduct().equals(BaseEnum.ProductEnum.CONSOLE.getName())) {
            example.and().andNotEqualTo("status", MobileConfigEnum.RechargeEnum.CLOSED.getCode());
        }
        return mobileRechargeRecordMapper.selectByExample(example);
    }

    public MobileRechargeRecord queryBySerialno(String serialno) {
        MobileRechargeRecord entity = new MobileRechargeRecord();
        entity.setSerialno(serialno);
        return selectOne(entity);
    }

    public MobileRechargeRecord getBySerialno(String orderId) {
        MobileRechargeRecord entity=new MobileRechargeRecord();
        entity.setSerialno(orderId);
        return selectOne(entity);
    }

    public List<StatisticsAmountVo> getAmount(MobileRechargeRecordPageBo pageBo) {
        return mobileRechargeRecordMapper.getAmount(pageBo);
    }

    public List<MobileRechargeRecord> getAll() {
        Example example = new Example(MobileRechargeRecord.class);
        return mobileRechargeRecordMapper.selectByExample(example);
    }

    public void changeId(Map<String, String> map) {
        mobileRechargeRecordMapper.changeId(map);
    }
}
